
#include "timer.h"

int time_tick;
int sec_tick; 

void timer_init(int timer, int mode)
{
	outportb(TIMER_CTRL,((timer<<6)| mode));
}


void timer_load(int timer, int value)
{
	timer_init(timer, LCOM_MODE);
	int note_freq = TIMER_CLK/value;
	switch(timer){
		case 0:	outportb(TIMER_0, LSB(note_freq));	
				outportb(TIMER_0, MSB(note_freq)); 
				break;
						
		case 2:	outportb(TIMER_2, LSB(note_freq));	
				outportb(TIMER_2, MSB(note_freq)); 
				break;
						
		default: outportb(TIMER_2, LSB(note_freq));
				 outportb(TIMER_2, MSB(note_freq));
				 break;
	}
}


void mili_sleep(int mili)
{
	int time_out = time_tick + mili;
	while(time_tick < time_out)
		;
}

void sec_sleep(int secs)
{
  int time_out = sec_tick + secs;
	while(sec_tick < time_out)
		;
}

/** @} end of TimerCounter */
